package com.sale.system.controller;

import com.sale.common.core.domain.R;
import com.sale.common.core.web.controller.BaseController;
import com.sale.common.log.annotation.Log;
import com.sale.common.log.enums.BusinessType;
import com.sale.common.mybatis.core.page.PageQuery;
import com.sale.common.mybatis.core.page.TableDataInfo;
import com.sale.system.domain.PullDown;
import com.sale.system.domain.dto.SysCategoryDto;
import com.sale.system.domain.vo.SysCategoryVo;
import com.sale.system.service.ISysCategoryService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @Description 类别管理
 * @Date 23-12-05
 * @Author hl
 **/
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/categoryMaterial")
public class SysCategoryController extends BaseController {

    private final ISysCategoryService sysCategoryService;

    /**
     * 类别管理
     */
    //@SaCheckPermission("finance:expenditure:list")
    @GetMapping("/list")
    public TableDataInfo<SysCategoryDto> list(SysCategoryVo sysCategoryVo, PageQuery pageQuery)
    {
        return sysCategoryService.selectCategoryList(sysCategoryVo,pageQuery);
    }

    /**
     * 新增类别管理
     */
    //@SaCheckPermission("finance:expenditure:add")
    @Log(title = "类别管理", businessType = BusinessType.INSERT)
    @PostMapping
    public R<Void> add(@Validated @RequestBody SysCategoryVo sysCategoryVo) {
        return toAjax(sysCategoryService.insertCategory(sysCategoryVo));
    }

    /**
     * 根据编号获取详细信息
     */
    //@SaCheckPermission("finance:expenditure:query")
    @GetMapping(value = "/{categoryId}")
    public R getInfo(@PathVariable long categoryId)
    {
        return R.ok(sysCategoryService.selectCategoryById(categoryId));
    }

    /**
     * 删除类别管理
     */
    //@SaCheckPermission("finance:expenditure:remove")
    @Log(title = "类别管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/remove/{categoryId}")
    public R<Void> remove(@PathVariable String categoryId) {
        return toAjax(sysCategoryService.deleteCategoryById(categoryId));
    }

    /**
     * 修改类别管理
     */
    //@SaCheckPermission("finance:expenditure:edit")
    @Log(title = "类别管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<Void> edit(@RequestBody SysCategoryVo sysCategoryVo) {
        return toAjax(sysCategoryService.updateCategoryEdit(sysCategoryVo));
    }

    /**
     * 下拉
     */
    @GetMapping("/listSel/{categoryType}")
    public R<List<PullDown>> list(@PathVariable String categoryType)
    {
        List<PullDown> list = sysCategoryService.selectCategorySelList(categoryType);
        return R.ok(list);
    }


}
